import axios from "axios";
import qs from "querystring";

// axios 配置
axios.defaults.timeout = 6000;
axios.defaults.baseURL = "";
axios.defaults.headers["Content-Type"] =
  "application/x-www-form-urlencoded; charset=UTF-8";

// http request 拦截器
axios.interceptors.request.use(
  config => {
    if (config.method.toLowerCase() === "post") {
      config.data = qs.stringify(config.data);
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// http response 拦截器
axios.interceptors.response.use(
  res => {
    return res;
  },
  error => {
    return Promise.reject(error);
  }
);

export default axios;
